<?php
/** Make sure that the WordPress bootstrap has run before continuing. */
require_once( '../wp-load.php' );
/* 
if ( !is_user_logged_in() ) { 
	header("Location: http://zy.oschina.mopaas.com/wp-login.php"); 
	exit;	
} 

if ( !is_user_logged_in() ) { 
	$time=1;
	$url = "http://zy.oschina.mopaas.com/wp-login.php";
	header("refresh:{$time};url={$url}"); 
	exit;
} 
*/

//------------get user_id
global $current_user;
get_currentuserinfo();
$user_id = $current_user->ID;
$user_name = $current_user->display_name;
/*
echo 'User ID: ' . $current_user->ID. "|";
echo 'Username: ' . $current_user->user_login . "|";
echo 'User email: ' . $current_user->user_email . "|";
echo 'User first name: ' . $current_user->user_firstname. "|";
echo 'User last name: ' . $current_user->user_lastname. "|";
echo 'User display name: ' . $current_user->display_name. "|";
*/
//------------


//-----------check if login
if ( !is_user_logged_in() || $user_id<1 ) { 
	$url = wp_login_url("index.php?page_id=22");
	echo "<script language='javascript' type='text/javascript'>";  
	echo "parent.location.href='$url'";  
	echo "</script>"; 
	exit;
} 

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>order_list</title>

<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.2.custom.css" />
<link rel="stylesheet" type="text/css" href="css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/fancybox.css" />

<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="js/jquery.fancybox.js" type="text/javascript"></script>
<script src="js/jquery.message.js" type="text/javascript"></script>

</head>

<body bgcolor="yellow">

<div id="main">

<h2 class="top_title">(<?php echo $user_name; ?>)我的订单</h2>

<div class="grid_table">
     <div id="opt">
        <div id="query">
            <!-- <label>订单号：</label> --><input type="hidden" class="input" id="order_id" /> 
            <label>包裹号：</label><input type="text" class="input" id="package_seq" />
			<label>订单状态：</label><select id="order_status" >
				<option value="" >--</option>
				<option value="10" >新订单</option>
				<option value="20" >待付款</option>
				<option value="30" >已付款</option>
				<option value="40" >待补款</option>
				<option value="45" >已补款</option>
				<option value="50" >已结束</option>				
			</select>			
            <input type="submit" class="btn" id="find_btn" value="查 询" />
        </div>
        <input type="button" class="btn" id="add_btn" value="新 增" />

     </div>
     <table id="list"></table>
     <div id="pager"></div>
</div>

&nbsp;
</div>

<div id="footer">
&nbsp;
</div>

<script type="text/javascript">
$("#list").jqGrid({
	url:'order_do.php?action=list&uid=<?php echo $user_id; ?>',  //请求数据的url地址
	datatype: "json",  //请求的数据类型
   	colNames:['订单号','物流商','包裹号','收件人','金额','物品名称','建单时间','订单状态','操作'], //数据列名称（数组）
   	colModel:[ //数据列各参数信息设置
   		{name:'id',index:'id', editable:true, width:60,align:'center', title:false},
		{name:'shipper',index:'shipper', width:40,align:'center', title:false},		
		{name:'package_seq',index:'package_seq', width:110},
		{name:'address_to_id',index:'address_to_id', width:60, title:false},   		
		{name:'fee_sum',index:'fee_sum', width:40, title:false},
   		{name:'package_name',index:'package_name', width:80, title:false},
		{name:'time_create',index:'time_create', width:60,align:'center', title:false},
		{name:'order_status',index:'order_status', width:100, title:false},
   		{name:'opt',index:'opt', width:110, sortable:false }		
   	],
   	rowNum:10, //每页显示记录数
   	rowList:[10,15,30], //分页选项，可以下拉选择每页显示记录数
   	pager: '#pager',  //表格数据关联的分页条，html元素
	autowidth: true, //自动匹配宽度
	height: 290,   //设置高度
	gridview:true, //加速显示
    viewrecords: true,  //显示总记录数
	multiselect: false,  //可多选，出现多选框
	multiselectWidth: 25, //设置多选列宽度
	sortable:true,  //可以排序
	sortname: 'id',  //排序字段名
    sortorder: "desc", //排序方式：倒序，本例中设置默认按id倒序排序
	loadComplete:function(data){ //完成服务器请求后，回调函数	
		if(data.records==0){ //如果没有记录返回，追加提示信息
			$("p").appendTo($("#list")).addClass("nodata").html('找不到相关数据！');
		}else{ //否则，删除提示，删除按钮可用
			$("p.nodata").remove();
		}
	}
 });
$(function(){
	$("#add_btn").click(function(){
		self.location='order_address.php';
	});
	
	$("#find_btn").click(function(){
		var order_status = escape($("#order_status").val()); //对字符串进行编码
		var package_seq = escape($("#package_seq").val()); //对字符串进行编码
	    var order_id = escape($("#order_id").val());       //对字符串进行编码
	    $("#list").jqGrid('setGridParam',{
			url:"order_do.php?action=list",
			postData:{'order_id':order_id, 'package_seq':package_seq,'order_status':order_status},
			page:1
		}).trigger("reloadGrid");
	});
});
</script>

</body>
</html>
